package com.shiroha.account.controller.advice;

import com.shiroha.common.exception.ServiceException;
import com.shiroha.common.exception.AuthenticationException;
import com.shiroha.common.exception.BadRequestException;
import com.shiroha.common.exception.InternalServiceException;
import com.shiroha.common.utils.Result;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(ServiceException.class)
    public Result<String> handleException(ServiceException e) {
        return Result.error(e.getErrorCode().value(), e.getMessage());
    }

    @ExceptionHandler(AuthenticationException.class)
    public ResponseEntity<String> handleAuthenticationException(AuthenticationException e) {
        return ResponseEntity.status(e.getErrorCode().value()).body(e.getMessage());
    }

    @ExceptionHandler(BadRequestException.class)
    public ResponseEntity<String> handleBadRequestException(BadRequestException e) {
        return ResponseEntity.status(e.getErrorCode().value()).body(e.getMessage());
    }

    @ExceptionHandler(InternalServiceException.class)
    public ResponseEntity<String> handleInternalServiceException(InternalServiceException e) {
        return ResponseEntity.status(e.getErrorCode().value()).body(e.getMessage());
    }
}
